package com.bjsxt.common.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.bjsxt.users.pojo.AAdmins;

/*
 * 登录拦截器
 */
@Component("adminsAuthInterceptor")
public class AdminsAuthInterceptor extends HandlerInterceptorAdapter
{

	//执行之前拦截
	@Override
	public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception
	{
		//从session中获取admins对象
		HttpSession session=request.getSession();
		AAdmins admins = (AAdmins) session.getAttribute("admins");
		if(admins != null)
		{
			//已经登录
			return true;
		}else
		{
			//非法访问
			String info="请先登录";
			session.setAttribute("info",info);
			response.sendRedirect(request.getContextPath()+"/adminsLogin.htm");
			return false;
		}
	}

}
